package org.summerframework.component.security.annotion;


import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.core.annotation.AliasFor;

import org.summerframework.component.security.resolver.id.CIDService;

/**
 * 帮助注入{@link org.summerframework.component.security.core.resolver.cid.CIDMethodArgumentsResolver}
 * <p>
 * 注入至方法中的{@link #cid()}和{@link #id()}
 * 或者CIDInterceptor.getContext()获取
 * <p>
 * <code>
 * <p>
 * &#064;CIDRequired(id="testId", cid="testCIDName")
 * &#064;RequestMapping
 * private ResultDTO<?> test(Long testId, String testCIDName) {
 * }
 * <p>
 * &#064;CIDRequired(isCreate = true)
 * &#064;RequestMapping("1")
 * private ResultDTO<?> test1() {
 * CIDInterceptor.getCID();
 * }
 * </code>
 * <p>
 * <p>
 * <p>
 * 如果需要注入方法中需要如下配置
 * <code>
 * <p>
 * <mvc:annotation-driven>
 * <mvc:argument-resolvers>
 * <bean id="myMethodArgumentsResolver" class="CIDMethodArgumentsResolver"/>
 * </mvc:argument-resolvers>
 * </mvc:annotation-driven>
 * </code>
 *
 * @author 石超
 * @version v1.0.0
 */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface CIDRequired {
    String ID = "id";
    String CID = "cid";

    @AliasFor("cidSerivce")
    Class<? extends CIDService> value() default CIDService.class;

    /**
     * request 中的cid的信息
     *
     * @return 名称
     */
    String cid() default CID;

    /**
     * 是否是新的创建
     *
     * @return true 创建, false request中获取
     */
    boolean isCreate() default false;

    /**
     * id的名称
     *
     * @return 名称
     */
    String id() default ID;

    @AliasFor("value")
    Class<? extends CIDService> cidSerivce() default CIDService.class;

    boolean isAuto() default true;
}
